<cfsetting enablecfoutputonly="yes">

<cfparam name="attributes.url" default="#application.xtiurl#">
<cfparam name="attributes.dtd" default="#application.xtidtd#">

<cfparam name="attributes.url" default="">
<cfparam name="attributes.dtd" default="">
<cfparam name="attributes.debug" default="false">
<cfparam name="attributes.return_false" default="0">
<cfparam name="attributes.debuglevel" default="1,2,3">
<cfparam name="attributes.customerid" default="">
<cfparam name="attributes.contactid" default="">
<cfparam name="attributes.contact_status" default="">
<cfparam name="attributes.type">
<!--- NAME INFO --->
<cfparam name="attributes.prefix" default="">
<cfparam name="attributes.first_name">
<cfparam name="attributes.midinit" default="">
<cfparam name="attributes.last_name">
<cfparam name="attributes.suffix" default="">
<cfparam name="attributes.abinum" default="">
<cfparam name="attributes.company_department">
<cfparam name="attributes.company_division" default="">
<!--- BILLING INFO --->
<cfparam name="attributes.b_company_name" default="">
<cfparam name="attributes.b_address1">
<cfparam name="attributes.b_address2" default="">
<cfparam name="attributes.b_city">
<cfparam name="attributes.b_state" default="">
<cfparam name="attributes.b_zip" default="">
<cfparam name="attributes.geo_code" default="">
<cfparam name="attributes.b_country">
<cfparam name="attributes.b_phone">
<cfparam name="attributes.b_ext" default="">
<!--- LITERATURE --->
<cfparam name="attributes.lit_query_add" default="">
<cfparam name="attributes.lit_query_delete" default="">
<!--- OTHER --->
<cfparam name="attributes.alt_phone" default="">
<cfparam name="attributes.alt_ext" default="">
<cfparam name="attributes.fax_phone" default="">
<cfparam name="attributes.email">
<cfparam name="attributes.web_response">
<cfparam name="attributes.web_challenge">
<cfparam name="attributes.flag_esf" default="Y">
<cfparam name="attributes.flag_spf" default="Y">
<cfparam name="attributes.source" default="web">
<cfparam name="attributes.user" default="web">
<cfparam name="attributes.pay_type" default="">
<cfparam name="attributes.account_active" default="">
<cfparam name="attributes.tax_resale_number" default="">
<cfparam name="attributes.tsr_own" default="">
<cfparam name="attributes.tsr_take" default="">
<cfparam name="attributes.avs_at_contact" default="">
<!----added P2666--->
<cfparam name="attributes.ds_loc" default="">
<cfparam name="attributes.auto_catalog" default="">
<!--- modified per project 4531 --->
<cfparam name="attributes.contact_type" default="">
<cfparam name="attributes.company_position" default="">
<!--- end of modification --->
<cfset attributes.b_company_name="#replace(attributes.b_company_name, "&", "and", "all")#">
<cfset attributes.b_address1="#replace(attributes.b_address1, "&", "and", "all")#">
<cfset attributes.b_address2="#replace(attributes.b_address2, "&", "and", "all")#">
<!--- Tag Constraints --->

<cfif attributes.return_false>
	<cfset temp = setvariable('caller.xti_createcustomer.result', false)>
	<cfsetting enablecfoutputonly="no">
	<cfexit method="exittag">
</cfif>

<cfset l_action="upd_contact">
<cfif attributes.type eq 'H'>
	<!--- Cannot Create contact (calltype) for home user --->
	<!--- update must be done at customer level for home accounts --->
	<cfset l_action="upd_cust">
<cfelse>
	<cfset calltype = "crt_contact">
</cfif>

<!--- Create XML for LIT_PAK tags - parse out the array
action A = add, action D = delete.
does customer want to recive catalogs? --->
<cfparam name="lit_pak_xml_delete" default="">
<cfparam name="lit_pak_xml_add" default="">

	<cfif isQuery(attributes.lit_query_add) and attributes.lit_query_add.recordcount>
		<cfset lit_pak_add=duplicate(attributes.lit_query_add)>

		
		<cfsavecontent variable="lit_pak_xml_add">
		<cfoutput query="lit_pak_add">
				<lit_pak>
				   <lit_name>#ucase(lit_pak_add.SUB_CODE)#</lit_name>
				   <lit_action>A</lit_action>
				 </lit_pak>
			</cfoutput>
		</cfsavecontent>
	</cfif>	
	

		<cfif isQuery(attributes.lit_query_delete) and attributes.lit_query_delete.recordcount>
		<cfset lit_pak_delete=attributes.lit_query_delete>
					
		<cfsavecontent variable="lit_pak_xml_delete">
		<cfoutput query="lit_pak_delete">
				<lit_pak>
				   <lit_name>#ucase(LIT_NAME)#</lit_name>
				   <lit_action>D</lit_action>
				 </lit_pak>
			</cfoutput>
		</cfsavecontent>
	</cfif>





<!--- <cfif isarray(attributes.lit_delete_array)>
	<cfscript>
	lit_pak_delete = "";
	indexcnt = arraylen(attributes.lit_delete_array) + 1;
	for ( i=1; i lt indexcnt ; i=i+1) {
	     lit_pak_delete = lit_pak_delete & '         
	 <lit_pak>
	   <lit_name>#ucase(attributes.lit_delete_array[i].lit_name)#</lit_name>
	   <lit_action>D</lit_action>
	 </lit_pak>';
	}
	</cfscript>
</cfif> --->

<!--- Build the xml to send to middleware--->
<cfscript>
xml = 
'<!DOCTYPE copy SYSTEM "#attributes.dtd#">
<xtiinput>
   <inputheader>
      <actionset>
         <action>#l_action#</action>
      </actionset>
   </inputheader>
   <inputdata>
      <customer>
         <customerid>#ucase(attributes.customerid)#</customerid>
         <contactid>#ucase(attributes.contactid)#</contactid>
		 <contact_status>#ucase(attributes.contact_status)#</contact_status>
         <type>#ucase(attributes.type)#</type>
         <prefix>#ucase(attributes.prefix)#</prefix>
         <first_name>#ucase(attributes.first_name)#</first_name>
         <midinit>#ucase(attributes.midinit)#</midinit>
         <last_name>#ucase(attributes.last_name)#</last_name>
         <suffix>#ucase(attributes.suffix)#</suffix>
         <abinum>#ucase(attributes.abinum)#</abinum>
         <company_department>#ucase(replacenocase(rereplace(attributes.company_department,"&","AND","ALL") , 'amp;', '', 'ALL'))#</company_department>
         <company_division>#ucase(replacenocase(rereplace(attributes.company_division,"&","AND","ALL") , 'amp;', '', 'ALL'))#</company_division>
		 <company_position>#ucase(replacenocase(rereplace(attributes.company_position,"&","AND","ALL") , 'amp;', '', 'ALL'))#</company_position>
		 <contact_type>#ucase(replacenocase(rereplace(attributes.contact_type,"&","AND","ALL") , 'amp;', '', 'ALL'))#</contact_type>
         <billing>
            <company_name>#ucase(replacenocase(rereplace(attributes.b_company_name,"&","AND","ALL") , 'amp;', '', 'ALL'))#</company_name>
            <address_1>#ucase(attributes.b_address1)#</address_1>
            <address_2>#ucase(attributes.b_address2)#</address_2>
            <city>#ucase(attributes.b_city)#</city>
            <state>#ucase(attributes.b_state)#</state>
            <zip>#ucase(attributes.b_zip)#</zip>
            <geo_code>#attributes.geo_code#</geo_code>
            <country>#ucase(attributes.b_country)#</country>
            <phone>#rereplace(attributes.b_phone, '[^0-9]', '', 'all')#</phone>
         </billing>
			#lit_pak_xml_add#
		 	#lit_pak_xml_delete#
         <ext>#ucase(attributes.b_ext)#</ext>
         <alt_phone>#rereplace(attributes.alt_phone, '[^0-9]', '', 'all')#</alt_phone>
         <alt_ext>#ucase(attributes.alt_ext)#</alt_ext>
         <fax_phone>#rereplace(attributes.fax_phone, '[^0-9]', '', 'all')#</fax_phone>
         <email>#attributes.email#</email>
         <web_response>#ucase(attributes.web_response)#</web_response>
         <web_challenge>#ucase(attributes.web_challenge)#</web_challenge>
         <esf>#ucase(attributes.flag_esf)#</esf>
         <spf>#ucase(attributes.flag_spf)#</spf>
         <source>#ucase(attributes.source)#</source>
         <user>#ucase(attributes.user)#</user>
         <pay_type>#ucase(attributes.pay_type)#</pay_type>
         <account_active>#ucase(attributes.account_active)#</account_active>
         <tax_resale_number>#ucase(attributes.tax_resale_number)#</tax_resale_number>
         <tsr_own>#ucase(attributes.tsr_own)#</tsr_own>
         <tsr_take>#ucase(attributes.tsr_take)#</tsr_take>
         <avs_at_contact>#ucase(attributes.avs_at_contact)#</avs_at_contact>
		 <auto_catalog>#ucase(attributes.auto_catalog)#</auto_catalog>
      </customer>
   </inputdata>
</xtiinput>';
</cfscript>